<%--
  Created by IntelliJ IDEA.
  User: 杨娇
  Date: 2025/7/2
  Time: 15:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 新能源充电系统</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
        }

        .container {
            display: flex;
            width: 100%;
        }

        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
        }

        .logo {
            text-align: center;
            padding: 20px 0;
            margin-bottom: 30px;
        }

        .logo-icon {
            width: 60px;
            height: 60px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 24px;
            color: var(--light-color);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            border: 2px solid rgba(255, 255, 255, 0.3);
        }

        .logo-text {
            font-size: 1.5rem;
            margin-top: 10px;
            font-weight: 500;
            background: linear-gradient(to right, var(--light-color), #fff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .menu-item {
            padding: 15px 25px;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .menu-item:hover {
            background-color: rgba(255, 255, 255, 0.1);
        }

        .menu-item.active {
            background-color: rgba(255, 255, 255, 0.2);
            border-left: 4px solid var(--light-color);
        }

        .menu-icon {
            margin-right: 10px;
            font-size: 18px;
            width: 24px;
            text-align: center;
        }

        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 20px;
        }

        .content-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #ddd;
        }

        .content-title {
            color: var(--dark-color);
            font-size: 1.8rem;
            font-weight: 500;
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-weight: 500;
            overflow: hidden;
        }

        .user-avatar img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .content-area {
            background-color: white;
            border-radius: 10px;
            box-shadow: var(--shadow);
            padding: 25px;
            min-height: 500px;
        }

        .hidden {
            display: none;
        }

        /* 公告样式 */
        .announcement-list {
            list-style: none;
            padding: 0;
        }

        .announcement-item {
            padding: 15px 0;
            border-bottom: 1px solid #eee;
            transition: var(--transition);
        }

        .announcement-item:hover {
            background-color: #f9f9f9;
        }

        .announcement-date {
            font-size: 0.85rem;
            color: var(--accent-color);
            margin-bottom: 5px;
        }

        .empty-state {
            text-align: center;
            padding: 30px;
            color: #777;
        }

        /* 地图样式 */
        .map-container {
            height: 500px;
            background-color: #eee;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
            position: relative;
            overflow: hidden;
        }

        .map-placeholder {
            color: #777;
            font-size: 1.2rem;
            text-align: center;
        }

        .station-list {
            list-style: none;
            padding: 0;
        }

        .station-item {
            padding: 12px 15px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .station-status {
            padding: 5px 10px;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 500;
        }

        .status-available {
            background-color: rgba(0, 200, 83, 0.1);
            color: #00c853;
        }

        .status-busy {
            background-color: rgba(255, 171, 0, 0.1);
            color: #ffab00;
        }

        /* 充电桩样式 */
        .search-bar {
            display: flex;
            justify-content: space-between;
            margin-bottom: 25px;
            gap: 15px;
        }

        .search-input {
            flex: 1;
            padding: 12px 15px 12px 45px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 15px;
            transition: var(--transition);
            background-color: #fafafa;
        }

        .search-input:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(0, 168, 150, 0.1);
            background-color: white;
        }

        .search-icon {
            position: absolute;
            left: 15px;
            top: 12px;
            color: #999;
            font-size: 18px;
        }

        .search-group {
            position: relative;
            flex: 1;
        }

        .filter-btn {
            padding: 12px 25px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 15px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .filter-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .pile-table {
            width: 100%;
            border-collapse: collapse;
        }

        .pile-table th {
            padding: 15px;
            text-align: left;
            background-color: #f5f5f5;
            font-weight: 500;
            color: #555;
        }

        .pile-table td {
            padding: 15px;
            border-bottom: 1px solid #eee;
        }

        .pile-table tr:hover {
            background-color: #f9f9f9;
        }

        .reserve-btn {
            padding: 8px 15px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            transition: var(--transition);
            box-shadow: 0 2px 10px rgba(0, 168, 150, 0.2);
        }

        .reserve-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 168, 150, 0.3);
        }

        .reserve-btn:disabled {
            background: #ccc;
            cursor: not-allowed;
            box-shadow: none;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
                height: auto;
                position: relative;
            }

            .main-content {
                margin-left: 0;
            }

            .search-bar {
                flex-direction: column;
            }

            .pile-table {
                display: block;
                overflow-x: auto;
            }
        }

        /* 充电桩详情按钮样式 - 绿色主题 */
        .pile-detail-btn {
            padding: 6px 12px;
            background-color: #2ecc71;       /* 主绿色 - 清新活力 */
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 14px;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            box-shadow: 0 2px 4px rgba(46, 204, 113, 0.3); /* 绿色阴影 */
        }

        .pile-detail-btn:hover {
            background-color: #27ae60;       /* 深绿色 - 悬停状态 */
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(46, 204, 113, 0.4); /* 增强阴影 */
        }

        .pile-detail-btn:active {
            background-color: #2ecc71;       /* 点击时恢复主色 */
            transform: translateY(0);
            box-shadow: 0 2px 4px rgba(46, 204, 113, 0.3); /* 点击阴影 */
        }

        /* 按钮图标样式 */
        .pile-detail-btn i {
            font-size: 16px;
            color: white;                    /* 图标颜色与文字统一 */
        }

        /* 表格样式优化 */
        .pile-table {
            width: 100%;
            border-collapse: collapse;
        }
        .pile-table th {
            padding: 15px;
            text-align: left;
            background-color: #f5f5f5;
            font-weight: 500;
            color: #555;
        }
        .pile-table td {
            padding: 15px;
            border-bottom: 1px solid #eee;
            vertical-align: middle; /* 单元格内容垂直居中 */
        }
        .pile-table tr:hover {
            background-color: #f9f9f9;
        }


    </style>
</head>
<body>
<div class="container">
    <!-- 侧边栏菜单 -->
    <div class="sidebar">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div class="logo-text">绿能充</div>
        </div>
        <ul class="menu">
            <li class="menu-item active" data-target="announcement">
                <div class="menu-icon"><i class="fas fa-bullhorn"></i></div>
                <div>公告</div>
            </li>
            <li class="menu-item" data-target="map">
                <div class="menu-icon"><i class="fas fa-map-marked-alt"></i></div>
                <div>地图</div>
            </li>
            <li class="menu-item" data-target="charging-pile">
                <div class="menu-icon"><i class="fas fa-plug"></i></div>
                <div>充电桩</div>
            </li>
        </ul>
    </div>

    <!-- 主内容区 -->
    <div class="main-content">
        <div class="content-header">
            <h1 class="content-title">公告</h1>
            <div class="user-info">
                <div class="user-avatar">
                    <img src="${user.avatar}" alt="头像" onclick="window.location.href='${pageContext.request.contextPath}/user/personCenter/${user.id}'">
                </div>
                <span>${user.username}，欢迎回来</span>
            </div>
        </div>

        <!-- 公告内容 -->
        <div id="announcement" class="content-area">
            <ul class="announcement-list">
                <c:forEach items="${announcementList}" var="announcement">
                    <li class="announcement-item">
                        <div class="announcement-date">
                            <fmt:formatDate value="${announcement.createTime}" pattern="yyyy-MM-dd" />
                        </div>
                        <div>${announcement.title}: ${announcement.content}</div>
                    </li>
                </c:forEach>

                <c:if test="${empty announcementList}">
                    <li class="announcement-item empty-state">
                        <div>暂无公告信息</div>
                    </li>
                </c:if>
            </ul>
        </div>

        <!-- 地图内容 -->
        <div id="map" class="content-area hidden">
            <div class="map-container">
                <div class="map-placeholder">
                    <i class="fas fa-map-marked-alt" style="font-size: 2rem; margin-bottom: 10px; display: block;"></i>
                    充电站地图
                </div>
            </div>

            <h3>附近充电站</h3>
            <ul class="station-list">
                <c:forEach items="${stationList}" var="station">
                    <li class="station-item">
                        <div>
                            <strong>${station.stationName}</strong> - 距离${station.distance}km
                        </div>
                        <div class="station-status ${station.availablePile < station.totalPile * 0.3 ? 'status-busy' : 'status-available'}">
                            空闲桩位: ${station.availablePile}/${station.totalPile}
                        </div>
                    </li>
                </c:forEach>

                <c:if test="${empty stationList}">
                    <li class="station-item empty-state">
                        <div>暂无充电站信息</div>
                    </li>
                </c:if>
            </ul>
        </div>

        <!-- 充电桩内容 -->
        <div id="charging-pile" class="content-area hidden">
            <div class="search-bar">
                <div class="search-group">
                    <i class="fas fa-search search-icon"></i>
                    <input type="text" class="search-input" placeholder="输入充电桩编号或位置" id="pileSearch">
                </div>
                <button class="filter-btn" id="pileFilter">筛选</button>
            </div>

            <!-- 充电桩列表表格 -->
            <table class="pile-table">
                <thead>
                <tr>
                    <th>充电桩编号</th>
                    <th>类型</th>
                    <th>状态</th>
                    <th>价格(元/度)</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="pileTableBody">
                <c:forEach items="${chargingPileList}" var="chargingPile">
                    <tr>
                        <td>${chargingPile.code}</td>
                        <td>${chargingPile.type == 'DC' ? '快充' : '慢充'}</td>
                        <td>
                            <c:choose>
                                <c:when test="${chargingPile.status == 'AVAILABLE'}">
                                    <span class="station-status status-available">空闲</span>
                                </c:when>
                                <c:when test="${chargingPile.status == 'CHARGING'}">
                                    <span class="station-status status-busy">使用中</span>
                                </c:when>
                                <c:otherwise>
                                    <span class="station-status status-busy">${chargingPile.status}</span>
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td>${chargingPile.price}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/user/pile/detail/${chargingPile.id}" class="pile-detail-btn">
                                <i class="fas fa-eye"></i> 查看详情
                            </a>
                        </td>
                    </tr>
                </c:forEach>
                <c:if test="${empty chargingPileList}">
                    <tr>
                        <td colspan="5" class="empty-state">暂无充电桩信息</td>
                    </tr>
                </c:if>
                </tbody>
            </table>
        </div>
    </div>
</div>

<script>
    // 菜单切换功能
    document.querySelectorAll('.menu-item').forEach(item => {
        item.addEventListener('click', function() {
            // 移除所有active类
            document.querySelectorAll('.menu-item').forEach(i => {
                i.classList.remove('active');
            });

            // 添加当前active类
            this.classList.add('active');

            // 获取目标内容区域
            const target = this.getAttribute('data-target');

            // 隐藏所有内容区域
            document.querySelectorAll('.content-area').forEach(area => {
                area.classList.add('hidden');
            });

            // 显示目标内容区域
            document.getElementById(target).classList.remove('hidden');

            // 更新标题
            document.querySelector('.content-title').textContent = this.querySelector('div:nth-child(2)').textContent;
        });
    });

    // 筛选功能
    document.getElementById('pileFilter').addEventListener('click', function() {
        const searchText = document.getElementById('pileSearch').value.toLowerCase();
        const rows = document.querySelectorAll('#pileTableBody tr');

        rows.forEach(row => {
            const text = row.textContent.toLowerCase();
            if(text.includes(searchText)) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        });
    });

    // 搜索功能
    document.getElementById('pileSearch').addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
            document.getElementById('pileFilter').click();
        }
    });

    // 预约按钮功能
    function reservePile(code) {
        if(confirm(`确定要预约充电桩 ${code} 吗？`)) {
            // 发送AJAX请求预约充电桩
            fetch('/user/pile/reserve', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({code: code})
            })
                .then(response => response.json())
                .then(data => {
                    if(data.success) {
                        alert(`已成功预约充电桩 ${code}`);
                        location.reload();
                    } else {
                        alert(data.message || '预约失败');
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('预约过程中发生错误');
                });
        }
    }
</script>
</body>
</html>
